<!DOCTYPE html>
<html>
<head>
    <title>BootstrapValidator demo</title>

    <link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="../dist/css/bootstrapValidator.css"/>

    <script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../dist/js/bootstrapValidator.js"></script>

    <!-- Support datetime picker plugin: http://eonasdan.github.io/bootstrap-datetimepicker/ -->
    <link rel="stylesheet" href="http://eonasdan.github.io/bootstrap-datetimepicker/content/bootstrap-datetimepicker.css"/>
    <script type="text/javascript" src="http://eonasdan.github.io/bootstrap-datetimepicker/scripts/moment.js"></script>
    <script type="text/javascript" src="http://eonasdan.github.io/bootstrap-datetimepicker/scripts/bootstrap-datetimepicker.js"></script>

    <style type="text/css">
    /* Override to make the feedback icons shown properly */
    .form-horizontal .has-feedback .form-control-feedback {
        top: 0;
        right: -15px;
    }
    .form-horizontal .has-feedback .input-group .form-control-feedback {
        top: 0;
        right: -30px;
    }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <!-- form: -->
            <section>
                <div class="col-lg-8 col-lg-offset-2">
                    <div class="page-header">
                        <h2>Date validator</h2>
                    </div>

                    <form id="defaultForm" method="post" class="form-horizontal" action="target.php">
                        <div class="form-group">
                            <label class="col-lg-3 control-label">MM/DD/YYYY</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="monthDayYear" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-3 control-label">YYYY-DD-MM</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="yearDayMonth" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-3 control-label">YYYY.MM.DD</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="yearMonthDay" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-3 control-label">MM/DD/YYYY h:m A</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="monthDayYearTime" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-3 control-label">YYYY-DD-MM h:m A</label>
                            <div class="col-lg-5">
                                <input type="text" class="form-control" name="yearDayMonthTime" />
                            </div>
                        </div>

                        <!-- datetime picker -->
                        <div class="form-group">
                            <label class="col-lg-3 control-label"><a href="http://eonasdan.github.io/bootstrap-datetimepicker/">DateTime Picker</a> (MM/DD/YYYY h:m A)</label>
                            <div class="col-lg-5">
                                <div class="input-group date" id="datetimePicker">
                                    <input type="text" class="form-control" name="datetimePicker" />
                                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-lg-9 col-lg-offset-3">
                                <button type="submit" class="btn btn-primary">Submit</button>
                            </div>
                        </div>
                    </form>
                </div>
            </section>
            <!-- :form -->
        </div>
    </div>

<script type="text/javascript">
$(document).ready(function() {
    $('#datetimePicker').datetimepicker();

    $('#defaultForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            monthDayYear: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'MM/DD/YYYY'
                    }
                }
            },
            yearDayMonth: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'YYYY-DD-MM'
                    }
                }
            },
            yearMonthDay: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'YYYY.MM.DD',
                        separator: '.'
                    }
                }
            },
            monthDayYearTime: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'MM/DD/YYYY h:m A'
                    }
                }
            },
            yearDayMonthTime: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'YYYY-DD-MM h:m A'
                    }
                }
            },
            datetimePicker: {
                validators: {
                    notEmpty: {
                        message: 'The date is required and cannot be empty'
                    },
                    date: {
                        format: 'MM/DD/YYYY h:m A'
                    }
                }
            }
        }
    });

    $('#datetimePicker')
        .on('dp.change dp.show', function(e) {
            // Validate the date when user change it
            $('#defaultForm').data('bootstrapValidator').revalidateField('datetimePicker');
            // You also can call it as following:
            // $('#defaultForm').bootstrapValidator('revalidateField', 'datetimePicker');
        });
});
</script>
</body>
</html>